<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
        	<div class="FXBR">
	            <div class="fieldBox">
	                <div class="label">客户名称</div>
	                <div class="field">
	                    <input name="certNm" id="certNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">身份证号码</div>
	                <div class="field">
	                    <input name="certNo" id="certNo" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">手机号码</div>
	                <div class="field">
	                    <input name="mp" id="mp" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
            </div>
            
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	               <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
<!-- 增加弹出框 -->
<div id="add_Html" style="display:none">
    <form id="add_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">客户名</div>
                <div class="field">
                    <input name="certNm" id="certNm2" type="text" class="ui-textbox" value="" validate="{required:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">身份证号</div>
                <div class="field">
                    <input name="idcard" id="idcard2" type="text" class="ui-textbox" value="" >
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">手机号</div>
                <div class="field">
                    <input name="moblie" id="moblie2" type="text" class="ui-textbox" value="">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">银行卡号</div>
                <div class="field">
                    <input name="bkNo" id="bkNo2" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">数据类型</div>
                <div class="field">
                    <input name="datTyp" id="datTyp2" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">三方结果</div>
                <div class="field">
                    <input name="checkResult" id="checkResult2" type="text" class="ui-textbox" value="" >
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">备注</div>
                <div class="field">
                    <input name="remark" id="remark2" type="text" class="ui-textbox" value="" >
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveNew_Btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>
<!-- 修改弹出框 -->
<div id="change_Html" style="display:none">
    <form id="change_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">客户名</div>
                <div class="field">
                    <input name="certNm" id="certNm3" type="text" class="ui-textbox" value="" validate="{required:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">身份证号</div>
                <div class="field">
                    <input name="idcard" id="idcard3" type="text" class="ui-textbox" value="" >
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">手机号</div>
                <div class="field">
                    <input name="moblie" id="moblie3" type="text" class="ui-textbox" value="">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">银行卡号</div>
                <div class="field">
                    <input name="bkNo" id="bkNo3" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">数据类型</div>
                <div class="field">
                    <input name="datTyp" id="datTyp3" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">三方结果</div>
                <div class="field">
                    <input name="checkResult" id="checkResult3" type="text" class="ui-textbox" value="" >
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">备注</div>
                <div class="field">
                    <input name="remark" id="remark3" type="text" class="ui-textbox" value="" >
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveChangeNew_Btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>
<script type="text/javascript">
var grid = null, callback=null;
var addId = {
		id:null,
}
$(function () {
    grid = $("#ligergrid1").ligerGrid({
        url: '<%=path%>/customer/cstChkEmtRec/initList.do',
        //delayLoad:true,
        method: 'get',
        columns: [
            { display: '客户名称', name: 'certNm', minWidth: 100 , align:'center', enabledSort:true},
	            { display: '手机号', name: 'mp', minWidth: 100 , align:'center', enabledSort:true},
	            { display: '证件类型', name: 'certTypCdNm', width: 80, enabledSort:true },
	            { display: '证件号', name: 'certNo', width: 150,align:'left', enabledSort:true},
	            { display: '银行账号', name: 'bkNo', width: 180, enabledSort:true},
	            { display: '要素类型', name: 'datTyp', width: 100, align:'center', enabledSort:true},
	            { display: '第三方结果', name: 'checkResult', width: 100, align:'center', enabledSort:true},
	            { display: '备注', name: 'remark', width: 100, align:'center', enabledSort:true},
	            { display: '创建时间', name: 'crtTm', width: 150 , render:renderDate, enabledSort:true},
	            {
                    display: '操作', name: '', minWidth: 150, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value){
                    	var h='<a class="sq-button-hasicon" href="javascript:toMfrModify(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')"><i class="sqBtnIco_4"></i>修改</a>';
	            		var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
		            		d+="'"+rowdata.id+"'";
		                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
	                	return h + d;
                    }
                }
        ],
        pageSize: 10,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: '100%',
        heightDiff: -2,
        rownumbers:true,
        frozen: false,
        allowUnSelectRow: true,
        alternatingRow: false,
        onBeforeShowData: function ()
        {
            //var grid = this;
            //grid.collapsedRows = [];
        }
    });
    grid.setHeight(100);

    $("#searchBar").ligerForm();

    $("#pageloading").hide();

    /* 查询 */
    $("#searchBtn").click(function (event) {
        var form = liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
    });
    
    /* 清空 */
    $("#clearBtn").click(function (event) {
        $("#resetBtn").click();  //重置 input-text
        $("#resetBtn").click();
    });
    callback = function () {
        grid.reload();
    };
    $("#addBtn").click(function(event) {
        $.ligerDialog.open({
            width: 400,
            //top: 100,
            title : '新增客户信息',
            target: $("#add_Html"),
            onHideDialog: function () {
                clearLigerForm("add_form");
            }
        });
        var ligerForm = $("#add_form").ligerForm({validate: true});
        
    });
    $("#saveNew_Btn").click(function(event) {
    	var form = liger.get("add_form");
        if (!form.valid()) {
        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = form.getData();
		var wait_dialog;
		$.ligerDialog.hide();
		$.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: '<%=path%>/customer/cstChkEmtRec/add.do',
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					grid.reload();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
    });
    $("#saveChangeNew_Btn").click(function(event) {
    	var form = liger.get("change_form");
        if (!form.valid()) {
        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = form.getData();
        $.extend(true, data, addId);
		var wait_dialog;
		$.ligerDialog.hide();
		$.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: '<%=path%>/customer/cstChkEmtRec/modify.do',
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					grid.reload();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
    });
});
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	function deleteRecord(id){
		  if(!id)return;
		  var isDel = 1;
		  $.ajax({
			  type:'POST',
			  dataType:'json',
			  data:{id:id,isDel:isDel},
			  url:'<%=path%>/customer/cstChkEmtRec/removeById.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "success"
						});
						grid.reload();
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				}
			});
	}
	function toMfrModify(id){
		if(!id)return;
		$.ajax({
			type: 'get',
			dataType:'json',
			data:{id:id},
			url: '<%=path%>/customer/cstChkEmtRec/getById.do',
			success:function(msg){
				if(msg.success == 1){
					openChange();//弹出修改框
					setData(msg.data);//设置数据
					addId.id = id;
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	function openChange(){
		$.ligerDialog.open({
	        width: 400,
	        top: 100,
	        title : '修改银行信息',
	        target: $("#change_Html"),
	        onHideDialog: function () {
	            clearLigerForm("change_form");
	        }
	    });
		$("#change_form").ligerForm({validate: true});
	}
	function setData(data){
		var form = new liger.get("change_form");
		form.setData({
			id:data.id,
			certNm:data.certNm,
			idcard:data.certNo,
			moblie:data.mp,
			bkNo:data.bkNo,
			datTyp:data.datTyp,
			checkResult:data.checkResult,
			remark:data.remark
		});
	}
</script>

</body>
</html>